<?php
/**
 * Created by PhpStorm.
 * User: denh
 * Date: 17/2/22
 * Time: 下午4:02
 */
class NewCourseController extends BaseController {

    public $data;

    function __construct($m = DEFAULT_CONTROLLER, $a = DEFAULT_METHOD) {

        parent::__construct($m, $a);
        //$this->redirectToWeixinForOpenid();

        $this->load_hprose();
        //$this->token = $this->get_UserCenterToken($this->openId());
       // $this->accout = $_SESSION['userCenter']['id'];

        logger()->logInfo("meeting_session:".var_export($_SESSION, true));

        $this->token = "9a6ac1b368b34719b3f28a4e5ca18138721f5ebde53f47588f70cf0d4fc5a186";
        $this->accout = "";
    }

    function index() {
        $page = $this->request('page', 1);
        $label = $this->request('label', 0);

        $page = $page - 1;
        if ($page < 0) $page = 0;

        $re1 = self::$hproseHttpClient->IndexController_classIndexByLabe($this->token, $page, $label);
        $list = $re1->result->cardList;

        //标签列表
        if (empty($_SESSION['specialList'])) {
            $re2 = self::$hproseHttpClient->SystemItemsController_getItems($this->token);
            $specialList = \Tools::object2array($re2->result);

            foreach ($specialList as $k => $v) {
                if (!(isset($v['isClassShow']) && $v['isClassShow'] == 1)) {
                    unset($specialList[$k]);
                }
            }
            $_SESSION['specialList'] = $specialList;
        } else {
            $specialList = $_SESSION['specialList'];
        }

        foreach ($list as $k=>$v) {
            foreach($specialList as $k_1 => $v_1) {
                if ($v->labe == $v_1['id']) {
                    $list[$k]->labal_name = $v_1['name'];
                    continue;
                }
            }
        }

        $this->data['list'] = json_encode($list);
        $this->data['specialList'] = json_encode($specialList);
        require $this->template;
    }

    function detail() {
        $课程id = (isset($_GET['id'])) ? $_GET['id'] : "0";

        $renzheng_url = $this->url('user','user_base');
        $yuyin_url = $this->url('course', 'course_detail', array("id" => $课程id));
        $course_shi_url = $this->url('course','video_chat', array('id'=>$课程id, 't'=> time()));

        $doUser = new Do用户();
        $doUser->set_openID($_SESSION['vo用户数据']['openID']);

        $re = $doUser->where($doUser->data)->row();
        #确认用户是否真的取关
        if ($doUser->get_unsubscribe() == 1 and $this->isSubscribe()) {
            $doUser->set_unsubscribe(0);
            $doUser->set_unsubscribe_time('');
            $doUser->save();
        }

        if (!$re or $doUser->get_unsubscribe() == 1) {
            $user_status = 1; #未关注

        } elseif ($doUser->get_认证() == 1) {
            $user_status = 2; #已关注 未认证
        } else {
            $user_status = 3; #已关注 已认证
        }

        if(isset($_GET['from'])|| empty($_SERVER['HTTP_REFERER'])) {
            $course_index_url = $this->url('course','index');
        } else {
            $course_index_url="javascript:history.go(-1);";
        }

        require $this->template;
    }


    function chat() {
        require $this->template;
    }
}